package com.sz.businessgroup.dao.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.HashMap;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;


import com.sz.businessgroup.dao.IBusinessGroupDAO;

import com.sz.common.SZUtility;

import com.sz.common.ICommonDAO;



public class BusinessGroupDAO extends SqlMapClientDaoSupport implements IBusinessGroupDAO
{
	
	protected final Log logger = LogFactory.getLog(getClass());
	
	private ICommonDAO commonDAO = null;
	
	public ICommonDAO getCommonDAO() {
		return commonDAO;
	}

	public void setCommonDAO(ICommonDAO commonDAO) {
		this.commonDAO = commonDAO;
	}

	@SuppressWarnings("unchecked")
	public List queryGroup(Map map) throws Exception {		
		List list = getSqlMapClient().queryForList("businessgroup_sqlmap.query_BusinessGroup", map);
		return addition(list);
	}
	
	@SuppressWarnings("unchecked")
	public long queryGroupCount(Map map) throws Exception {
		Map r = (Map)getSqlMapClient().queryForObject("businessgroup_sqlmap.query_BusinessGroupCount", map);
		return Long.parseLong(r.get("COUNT").toString());
	}
	
	@SuppressWarnings("unchecked")
	public List queryGroupPage(Map map) throws Exception {
		List list = getSqlMapClient().queryForList("businessgroup_sqlmap.query_BusinessGroupPage", map);
		return addition(list);
	}
	
	public long addBusinessGroup(Map map) throws Exception {
		Object obj = getSqlMapClient().insert("businessgroup_sqlmap.insert_BusinessGroup", map);
		return obj==null ? 0 : Long.parseLong(obj.toString());
	}
	
	@SuppressWarnings("unchecked")
	public List queryBusinessGroupDetail(Map map) throws Exception{
		List list = getSqlMapClient().queryForList("businessgroup_sqlmap.query_BusinessGroup_Detail", map);
		return addition(list);	
	}
	
	public long updateBusinessGroup(Map map) throws Exception {
		Object obj = getSqlMapClient().insert("businessgroup_sqlmap.update_BusinessGroup", map);
		return obj==null ? 0 : Long.parseLong(obj.toString());
	}
	
	/**
	 * �ڲ�ʹ��
	 * @param list
	 * @return
	 */
	@SuppressWarnings("unchecked")	
	private List addition(List list) {		
		if(list == null) return null;
		
		return list;
	}
}
